home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / (A)Z / (A)Z7.ADF / Execute / YesNo / yesno.c < prev   
C/C++ Source or Header  |  1986-10-31  |  2KB  |  60 lines

  1. /*==========================
  2. amiga/programs #26, from jdow, 1392 chars, Sun Feb 16 16:30:35 1986
  3. --------------------------
  4. TITLE: yesno.c
  5. I found a need in "execute" files to have operator intervention control
  6. the direction a batch file may take. The yesno.c program gives me a
  7. certain amount of control over this. I made little effort to get elegant
  8. as I could see little savings or benefit.
  9.  *
  10.  *
  11.  * yesno.c
  12.  *
  13.  * Version 1.0 (original release)
  14.  *
  15.  * Usage:
  16.  *      yesno "match string" <-c>
  17.  *      yesno prompts for operator input and compares it to the string.
  18.  *      if the -c option is present both strings are converted to caps before
  19.  *      the comparison.
  20.  *
  21.  * Copyright 14-Feb-86  by Joanne Dow   - released for free distribution as
  22.  * long as this copyright notice is retained in the file.
  23.  *
  24.  */
  25.  
  26. #include "stdio.h"
  27. #include "ctype.h"
  28.  
  29. #define NO      6       /* > warn level exit code */
  30. #define YES     0       /* No warning exit code   */
  31. #define SIZE    81      /* Size of read buffer      */
  32.  
  33. main(argc, argv)
  34. char *argv[];
  35. {
  36. int caps;
  37. char chxxx[SIZE], *pch;
  38.  
  39. if (argc <= 1)
  40.         {
  41.         printf("No arguments\n");
  42.         exit(NO);               /* exit false */
  43.         }
  44. caps = ((argc > 1) && (argv[2][0] == '-') && (argv[2][1]) == 'c');
  45.   
  46. pch = fgets( &chxxx[0], SIZE, stdin);
  47. chxxx[strlen(pch)-1] = '\0';
  48. if (caps)
  49.         {
  50.         while (*pch = toupper(*pch)) pch++;
  51.         printf("\n");
  52.         pch = argv[1];
  53.         while (*pch = toupper(*pch)) pch++;
  54.         pch = &chxxx[0];
  55.         }
  56. if (strcmp(argv[1], pch) == 0) exit(YES);
  57. else exit(NO);
  58. }
  59.  
  60.